<?php
namespace app\index\controller;
use think\Controller;
use app\common\controller\HomeBase;
//app下载
class Appxz extends HomeBase
{
     public function index()
    {
    	 //查询对应的数据
		    $cid=input('cid');
		    $oneData=db('category')->where('cid',$cid)->find();
		 
		   	   //二级导航的全部数据
		  
		     if($oneData['pid'] == 0){
		     	
		    	$cids=$this->getSon(db('category')->order('sort asc')->select(),$oneData['cid']);
		    	if(!empty($cids)){
		    		foreach($cids as $k=>$v){
		    		$arr[]=db('category')->where('cid',$v)->find();
		    	   }
		    	   $cid=$cids[0];
		    	   $oneData=db('article')->where('cid',$cid)->find();
		    	}
		    	
		    	
		    }else{
		    	
		    	$cids=$this->getSon(db('category')->order('sort asc')->select(),$oneData['pid']);
		    	if(!empty($cids)){
		    		foreach($cids as $k=>$v){
		    		$arr[]=db('category')->where('cid',$v)->find();
		    	   }
		    	}
		         $cid=$cid;
		         $oneData=db('article')->where('cid',$cid)->find();
		    }
		     if(!empty($oneData)){
		         $this->assign('oneData',$oneData);
		     } 
//		      var_dump($oneData);
		    if($cid){
		    	$this->assign('cid',$cid);
		    }
//		    var_dump($cid);
            if(!empty($arr)){
            	 $this->assign('arr',$arr);
            }
//		    halt($arr);
	        return $this->fetch();
    }
    
 
    

}
